#include "sematic.h"

bool sematic::isValidCircle(
							float x0, float y0, 
							float x1, float y1, 
							float i, float j
							){

	float r0, r1;
	
	x0 += i;
	y0 += j;
	r0 = sqrt(i*i + j*j);
	r1 = sqrt((x1 - x0)*(x1 - x0) + (y1 - y0)*(y1 - y0));
    if(r0 - GAP < r1 && r1 < r0 + GAP){
		return true;
	}
	return false;

}

bool sematic::isValidCircle(
						float x0, float y0, 
						float x1, float y1,
						float r
						){

    r = (2 * r + GAP) * (2 * r + GAP);

    if((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) < r)
		return true;
	return false;
	
}

void sematic::getIJCoordinates(
							float s[2], float r,
							float x0, float y0, 
							float x1, float y1, 
							int p
						){

	float v, d, cx, cy;
	
	p = p == TYPE_ARC_CLOCK ? -1: 1;
	p *= r < 0 ? -1: 1;
	d = sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
	cx = (x1 - x0) / 2.0;
	cy = (y1 - y0) / 2.0;
	v = sqrt(r * r - (d / 2.0) * (d / 2.0));
	s[0] = cx + (y0 - y1) * v / d * p;
	s[1] = cy + (x1 - x0) * v / d * p;

}

bool sematic::isUniqName(gObjectContainer &container, std::string &name){

	unsigned i;
	
	for(i = 0; i < container.size() - 1; i++)
		if(container[i]->getName() == name)
			return false;
	return true;
	
}
